package 字节;

import java.util.HashMap;

public class 无重复字符的最长子串 {
    public int lengthOfLongestSubstring(String s) {
         HashMap<Character, Integer> hashMap=new HashMap<>();
         int left=0,right=0;
         int res=0;
         while (right<s.length()){
             char c=s.charAt(right);
             right++;
             int ci=hashMap.getOrDefault(c,0);
             hashMap.put(c,++ci);
             while (hashMap.get(c)>1){
                 char d=s.charAt(left);
                 left++;
                 int cil=hashMap.getOrDefault(d,0);
                 hashMap.put(d,--cil);
             }

             res=Math.max(res,right-left);
         }
         return res;
    }

}
